package com.koron.operation.classes.form.controller;


import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.operation.classes.form.bean.po.ClassesFormRank;
import com.koron.operation.classes.form.service.ClassesFormRankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

/**
 * 月度排班表岗位配置(ClassesFormRank)表控制层
 *
 * @author jzp
 * @since 2023-07-18 17:50:57
 */
@Api(tags = "月度排班表岗位配置接口")
@RestController
@RequestMapping("classesFormRank")
public class ClassesFormRankController {
    /**
     * 服务对象
     */
    @Autowired
    private ClassesFormRankService classesFormRankService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "列表查询")
    @GetMapping("list")
    public Response<PageInfo<ClassesFormRank>> list(ClassesFormRank query) {
        Assert.notNull(query.getDeptId(), "部门查询条件不能为空");
        PageQuery pageQuery = PageQuery.newListQuery();
        return Response.ok(ADOConnection.runTask(getCurrDs(), classesFormRankService, "page", PageInfo.class, pageQuery, query));
    }

    @ApiOperation(value = "分页")
    @GetMapping("page")
    public Response<PageInfo<ClassesFormRank>> page(PageQuery pageQuery, ClassesFormRank query) {
        Assert.notNull(query.getDeptId(), "部门查询条件不能为空");
        return Response.ok(ADOConnection.runTask(getCurrDs(), classesFormRankService, "page", PageInfo.class, pageQuery, query));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping
    public Response<ClassesFormRank> selectOne(@RequestParam String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), classesFormRankService, "getById", ClassesFormRank.class, id));
    }

    @ApiOperation(value = "保存或更新数据")
    @PostMapping
    public Response<ClassesFormRank> save(@RequestBody ClassesFormRank classesFormRank) {
        ADOConnection.runTask(getCurrDs(), classesFormRankService, "save", Boolean.class, classesFormRank);
        return Response.ok(classesFormRank);
    }

    @ApiOperation(value = "删除数据")
    @DeleteMapping
    public Response<String> delete(@RequestParam String id) {
        ADOConnection.runTask(getCurrDs(), classesFormRankService, "deleteById", Boolean.class, id);
        return Response.ok();
    }

}
